package com.example.demo.controller;

import net.dreamlu.mica.ip2region.core.Ip2regionSearcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Controller
public class test {
    @Autowired
    private Ip2regionSearcher ip2regionSearcher;

    /**
     * 获取地理位置信息
     *
     * @param
     * @return
     */
    @GetMapping("test")
    @ResponseBody
    public String test() throws UnknownHostException {
        String ip = InetAddress.getLocalHost().getHostAddress();
        String address = ip2regionSearcher.getAddress(ip);
        return address;
    }

}
